/**
 * Project Name:ylbx
 * File Name:AbstractStatDataSource.java
 * Package Name:dln.stat.impl
 * Copyright (c) 2014, All Rights Reserved.
 *
 */
package dln.stat.ds;

import java.util.List;

import net.bat.db.BaseDAO;
import net.bat.db.BaseDAOImpl;
import net.ghy.statistics.utils.EUtils;

/**
 * ClassName: AbstractStatDataSource <br/>
 * Function: 报销统计基类
 * date: May 24, 2014 11:02:47 AM <br/>
 *
 * @author $dev
 * @version 1.0
 */
public abstract class AbstractStatDataSource<T> implements StatDataSource<T> {
    
    private List<T> result;
    
    public BaseDAO getDao() {
        return (BaseDAOImpl) EUtils.getCtx().getBean("BaseDAOImpl");
    }

    /* (non-Javadoc)
     * @see dln.stat.StatDataSource#generate(java.lang.Object[])
     */
    @Override
    public StatDataSource<T> generate(Object... parameters) {
        List<?> list = getDao().findByNamedQuery(getNameQuery(), parameters);
        result = listProcesser(list);
        return this;
    }

    /**
     * @param list
     * @return
     */
    protected abstract List<T> listProcesser(List<?> list);

    /**
     * @return
     */
    protected String getNameQuery() {
        return getClass().getName();
    }

    /* (non-Javadoc)
     * @see dln.stat.StatDataSource#getResult()
     */
    @Override
    public List<T> getResult() {
        return result;
    }

}
